package com.wenli.lt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.wenli.lt.entity.Fans;
import com.wenli.lt.entity.User;
import com.wenli.lt.mapper.FansMapper;
import com.wenli.lt.mapper.UserMapper;
import com.wenli.lt.service.IFansService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lt
 * @since 2021-03-24
 */
@Service
public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IFansService {

    @Autowired
    FansMapper fansMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List getFansInfoByNo(String studentNumber, Integer status) {
        if (!ObjectUtils.isNull(status)){
            if (0 == status){
                return userMapper.getFansInfoByNo(studentNumber);

            }else if(1 == status){
                return userMapper.getbeFansInfoByNo(studentNumber);

            }else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public boolean addBeFans(Fans fans) {
        fans.setFansId(UUID.randomUUID().toString().replace("-",""));
        return 1 == fansMapper.insert(fans);
    }

    @Override
    public boolean cancelBeFans(String focusId,String befocusId) {
        QueryWrapper<Fans> queryWrapper = new QueryWrapper();
        queryWrapper.eq("focusId",focusId);
        queryWrapper.eq("befocusId",befocusId);
        Fans fans = fansMapper.selectOne(queryWrapper);
        return 1 == fansMapper.deleteById(fans.getFansId());
    }
}
